package com.qf.adminController;

import com.qf.DBUtil.StringUtils;
import com.qf.adminService.AdminOrderService;
import com.qf.pojo.Order;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.adminController
 * @Description:
 * @Date 2022/10/4 20:41
 */
@RestController
@RequestMapping("/order")
public class AdminOrderController {

    @Autowired
    AdminOrderService adminOrderService;
    @Autowired
    UserService userService;

    @RequestMapping("/getAllOrder")
    public ModelAndView getAllOrder(ModelAndView mav){
        List<Order> allOrder = adminOrderService.getAllOrder();
        mav.addObject("orderList",allOrder);
        mav.setViewName("forward:/admin/showAllOrder.jsp");
        return mav;
    }

    @RequestMapping("/searchOrder")
    public ModelAndView searchOrder(String username,String statusNew,ModelAndView view){
        User user = userService.findByUsername(username);
        String uid;
        if (StringUtils.isEmpty(username)){
            uid = null;
        }else {
            uid=String.valueOf(user.getId());
        }
        List<Order> orderList = adminOrderService.selectOrder(uid,statusNew);
        view.addObject("orderList",orderList);
        view.setViewName("forward:/admin/showAllOrder.jsp");
        return view;
    }

    @RequestMapping("/sendOrder")
    public ModelAndView sendOrder(String oid,ModelAndView view){
        adminOrderService.sendOrder(oid);
        view.setViewName("redirect:/order/getAllOrder");
        return view;

    }
}
